package com.example.introductiontoprogramming;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Programming1 extends AppCompatActivity {


    private EditText edtTxtMaina, edtTxtMainb;
    private Button btnMainJisuan;
    private TextView tvMainResult;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.programming_main1);
        initView();
    }

    private void initView() {
        edtTxtMaina = (EditText) findViewById(R.id.edtTxtMaina);
        edtTxtMainb = (EditText) findViewById(R.id.edtTxtMainb);
        btnMainJisuan = (Button) findViewById(R.id.btnMainJisuan);
        tvMainResult = (TextView) findViewById(R.id.tvMainResult);
    }

    public void resultonClick(View view) {
        String a = edtTxtMaina.getText().toString();
        String b = edtTxtMainb.getText().toString();

        if (a.length() == 0 || b.length() == 0) {
            Toast.makeText(Programming1.this, "请输入数字", Toast.LENGTH_SHORT).show();
        } else {
            //将获取到的字符串转换成整型
            int c = Integer.parseInt(a) + Integer.parseInt(b);

            tvMainResult.setText(String.valueOf(c));
        }

    }
}